import axios from 'axios';
import {PageParams, PageResult} from '@/types/page'
import {Data} from '@arco-design/web-vue/es/_utils/types';


export interface QueryTagDto {
    id: number,
    tagName: string,
    isParent: number,
    parentId: number
}

export interface ParentTagVo {
    id: number,
    name: string
}

export interface ProblemTag {
    id?: number,
    updateTime?: Data,
    parentId?: number,
    isParent?: number,
    name?: string
}

export function generateProblemTag(): ProblemTag {
    return {
        id: undefined,
        updateTime: undefined,
        parentId: 0,
        isParent: 0,
        name: ""
    };
}

export interface TagTreeShowVo {
    id: number,
    name: string,
    children: TagTreeShowVo[]
}

export function getParentTag() {
    return axios.get<ParentTagVo[]>('/problem/open/parent-tag');
}

export function searchProblemTagByPage(params: PageParams, data: QueryTagDto) {
    return axios.post<PageResult<ProblemTag>>(`/problem/open/search-tag?current=${params.current}&pageSize=${params.pageSize}`, data);
}

export function addTag(data: ProblemTag) {
    return axios.post('/problem/close/tag/save', data)
}

export function updateTag(data: ProblemTag) {
    return axios.post('/problem/close/tag/update', data)
}

export function delTag(params: { tagId: number }) {
    return axios.get('/problem/close/tag/del', {params})
}

export function getTagTree() {
    return axios.get('/problem/open/tree-tag');
}


export interface QueryInfoDto {
    difficulty: number,
    isPrecise: number,
    tagIds: number[],
    title: string
}

export interface ProblemPageShowVo {
    id: number,
    title: string,
    difficulty: number,
    commitCount: number,
    correctCount: number,
    commitStatus?: number,
    isPublic: number,
    updateTime: Data
}

export interface SaveProblemDto {
    id?: number,
    difficulty: number,
    introduction: string,
    memoryLimit: number | null,
    timeLimit: number | null,
    inputSample: string,
    outputSample: string,
    problemExplain: string,
    tags: number[],
    title: string,
    isPublic: number
}

export function generateSaveProblem(): SaveProblemDto {
    return {
        id: undefined,
        difficulty: 1,
        introduction: "",
        memoryLimit: null,
        timeLimit: null,
        inputSample: "",
        outputSample: "",
        problemExplain: "",
        tags: [],
        title: "",
        isPublic: 0,
    };
}

export function searchInfoByPage(params: PageParams, data: QueryInfoDto) {
    return axios.post<PageResult<ProblemPageShowVo>>(`/problem/close/search-info?current=${params.current}&pageSize=${params.pageSize}`, data);
}

export function saveProblemInfo(data: SaveProblemDto) {
    return axios.post(`/problem/close/info/save`, data);
}

export function updateProblemSample(
    data: FormData,
) {
    return axios.post('/problem/close/info/update-sample', data);
}

export function updateProblemInfo(data: SaveProblemDto) {
	return axios.post('/problem/close/info/update-info',data)
}

export function getProblemInfo(params: { problemId: number }){
    return axios.get<SaveProblemDto>('/problem/close/detail-info', {params});
}
